package com.aia.ilp.web;

import java.io.File;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.util.StringUtils;

import com.aia.ilp.service.MainService;
import com.aia.ilp.webinterface.LatestCusts;
import com.aia.ilp.webinterface.Pageable;
import com.aia.ilp.webinterface.TopCusts;
import com.cfh.util.Tools;
import com.cfh.web.PageBean;
import com.opensymphony.xwork2.ActionSupport;

public class PublicUploadAction extends ActionSupport implements TopCusts, Pageable, LatestCusts, SessionAware {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(PublicUploadAction.class);

	private static final long serialVersionUID = 1L;
	private List topCusts;
	private List latestCusts;
	private MainService mainService;
	private File image;
	private String imageFileName;
	private PageBean pageBean = new PageBean();
	private String search;
	private String mydream;
	public Map getSession() {
		return session;
	}

	public void setSession(Map session) {
		this.session = session;
	}

	private Map session;

	private int page = 1;
	private int pageSize = 6;
	/***
	 * nouse
	 */
	public String execute() {
		if (logger.isDebugEnabled()) {
			logger.debug("execute() - start"); //$NON-NLS-1$
		}
		mainService.prepareTopCusts(this);

		// 用户可以不上传图片，这里仅对上传了图片的情况进行验证
		if (StringUtils.hasText(imageFileName) && image != null) {
			if (imageFileName.toLowerCase().endsWith(".jpg") || imageFileName.toLowerCase().endsWith(".png")
					|| imageFileName.toLowerCase().endsWith(".gif")) {
			} else {
				this.addActionError("请选择jpg或png格式的图片");
				return INPUT;
			}

			if (image.length() > 1024 * 1024) {
				this.addActionError("您选择的文件大小超过了1024KB");
				return INPUT;
			}
		}

		logger.debug("execute()"); //$NON-NLS-1$
		logger.debug("execute()"); //$NON-NLS-1$
		logger.debug("execute()"); //$NON-NLS-1$
		if (StringUtils.hasText(imageFileName) && image != null) {
			logger.debug("execute()"); //$NON-NLS-1$
			logger.debug("execute()"); //$NON-NLS-1$
		}
		mainService.updateDreamPic(this);

		String returnString = Tools.smartReturn((ActionSupport) this);
		if (logger.isDebugEnabled()) {
			logger.debug("execute() - end"); //$NON-NLS-1$
		}
		return returnString;

	}

	public List getTopCusts() {
		return topCusts;
	}

	public void setTopCusts(List list) {
		topCusts = list;
	}

	public void setMainService(MainService mainService) {
		this.mainService = mainService;
	}

	public MainService getMainService() {
		return mainService;
	}

	public void setLatestCusts(List latestCusts) {
		this.latestCusts = latestCusts;
	}

	public List getLatestCusts() {
		return latestCusts;
	}

	public void setPageBean(PageBean pageBean) {
		this.pageBean = pageBean;
	}

	public PageBean getPageBean() {
		return pageBean;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getPage() {
		return page;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setSearch(String search) {
		this.search = search;
	}

	public String getSearch() {
		return search;
	}

	public void setImage(File image) {
		this.image = image;
	}

	public File getImage() {
		return image;
	}

	public void setImageFileName(String imageFileName) {
		this.imageFileName = imageFileName;
	}

	public String getImageFileName() {
		return imageFileName;
	}

	public void setMydream(String mydream) {
		this.mydream = mydream;
	}

	public String getMydream() {
		return mydream;
	}

}
